<?php

//echo br(3); ###########################################################################################

	$TEMP->set_file(array('handle' => DIR_VIEW_REGISTRAR . 'studentIncGrade.html'));
	
	$urlPage 	= _GET('page');
		
	$listCountStudentInformation = $STUD->getStudentsIncGradeCount($_GET); //COUNT

	if( $listCountStudentInformation > 0 ) {
		$countNum			= 20;
		$pagenum 			= $_GET["page_no"];
		$page_rows 			= $PAGINATION->numPerRow($countNum);
		$last 				= $PAGINATION->lastCeilPerRow($listCountStudentInformation, $page_rows);
		$pagenum 			= $PAGINATION->pageNumRow($pagenum, $last); 
		$pageLimit 			= $PAGINATION->limitRow($pagenum, $page_rows);
		
		$arrBut				= array('first' 	=> '<img src="' . DIR_IMAGES . 'pagination_first.png" title="First" border="0" />',
									'previous' 	=> '<img src="' . DIR_IMAGES . 'pagination_prev.png" title="Previous" border="0" />',
									'next' 		=> '<img src="' . DIR_IMAGES . 'pagination_next.png" title="Next" border="0" />',
									'last' 		=> '<img src="' . DIR_IMAGES . 'pagination_last.png" title="Last" border="0" />',);
		$classCSS			= array('button' 	=> 'pagination-button', 'label' 	=> 'pagination-label');
		$urlGet				= array('hash' => hashRandom($_GET), 'page' => $_GET['page'], 'txtstudno' 	=> $_GET['txtstudno'], 'txtsemester' => $_GET['txtsemester'], 'txtsubject' => $_GET['txtsubject'], 'subButton' => $_GET['subButton']);
		
		if( $listCountStudentInformation > $countNum ) {
			$pagination 	= $PAGINATION->pagination($arrBut, $pagenum, $last, $classCSS, $urlGet);
		}
	}
	
	$studList = $STUD->getStudentsIncGrade($_GET, $pageLimit);
	
	# LSITING
	//r_print($studList );
	if ( !empty($studList) ) {
		
		$headerTable = '<tr class="tr-header">
							<td width="85" class="td-label">Student #</td>
							<td width="190" class="td-label">Name</td>
							<td width="140" class="td-label">Course/Subject</td>
							<td width="80" class="td-label">Section</td>
							<td width="260" class="td-label" colspan="3">Final Grade</td>
						</tr>';
		
		$TEMP->set_block('handle',  'students', 'studentsRow');
		$numCount 	 = 1;
		$bgcolor  	 = LOOPING_F0F;
		$viewPFID	 = '';
		$viewConvert = '';
			
		foreach($studList as $studListField => $studListValue) {
			
			$studID 	  		= $studListValue['stud_idPK'];
			$courseID 	  		= $studListValue['course_idFK'];
			$subjectID 	  		= $studListValue['subj_idFK'];
			$studSubjLinkerID	= $studListValue['stud_subj_linker_idPK'];
			$studGrade			= $studListValue['grade'];
			
			$studentSubjectGrades = $STUD->getStudentSubjectGrades($studID, $subjectID, $courseID, $SLID);

			$studSubjDescription  = $studentSubjectGrades['description'];
			$studSubjEquivalence  = $studentSubjectGrades['equivalence'];

			if (!empty($studGrade)) {
				if ( $studGrade == 'INC' )
					$subjDescription = '<span class="font-red">Incomplete</span>';
				elseif ( $studGrade == 'DRP' )
					$subjDescription = '<span class="font-red">Drop</span>';
				else {
					$subjDescription = $studSubjDescription;
				}
			}
			else {
				$subjDescription = $studSubjDescription;
			}
			
			$viewConvert  = '<div class="transfery-convertion" id="transfery_grades'. $studID .'">';
			$viewConvert .= (!empty($studSubjEquivalence)) ? $studSubjEquivalence : '';
			$viewConvert .= '</div>';
			
			$viewPFID  	  = '<div class="transfery-convertion" id="transfery_pfid'. $studID .'">';
			$viewPFID 	 .= (!empty($subjDescription)) ? $subjDescription : '';
			$viewConvert .= '</div>';
			
			$inputGrades = '<input type="hidden" id="id_transfer'. $studID .'" value="' . $studSubjLinkerID . '"/>
							<input type="text" class="input-transfer-text" maxlength="5" value="' . $studGrade . '" id="input_transfer'. $studID .'"/>
							<img src="' . DIR_IMAGES . 'icon/save.png" border="0" id="save_transfer'. $studID .'" class="cursor-pointer margin-transfery-top" onclick="saveGradeInput(\'' . $studID . '\', \'' . $SID . '\', \'' . $courseID. '\', \'' . $SLID . '\',  \'' . $activeYear . '\')"/>';
			
			$TEMP->set_var(array('stud_no'		=> $studListValue['stud_no'],
								 'name'			=> $studListValue['last_name'] . ', ' . $studListValue['first_name'] . ' ' . substr($studListValue['middle_name'],0,1) .'.',
								 'section'		=> $studListValue['section_desc'],
								 'course_subject'=> $studListValue['course_code'] . ' / ' . $studListValue['subj_code'],
								 'grades'		=> $inputGrades,
								 'convertion'	=> $viewConvert,
								 'description'	=> $viewPFID,
								 'numbering'	=> $numCount,
								));
			
			$TEMP->parse('studentsRow', 'students', true);
			$bgcolor = ($bgcolor == LOOPING_F0F) ? LOOPING_FFF : LOOPING_F0F;
			$numCount++;
		}
	}
	else {
		$TEMP->set_var(array('stud_no'		=> '',
							 'name'			=> 'No Record Found.',
							 'section'		=> '',
							 'course_subject'=> '',
							 'grades'		=> '',
							 'convertion'	=> '',
							 'description'	=> '',
							 'numbering'	=> '',
							));
	}
	
	
	$selectSemesterList = $DSC->getListSemestersDefault();
	$selectSemesterHTML = '<select name="txtsemester" id="txtsemester" class="select-auto-input"><option value=""></option>';
		foreach($selectSemesterList as $semesterListVal) {
			$semesterHTML = ( $_GET['txtsemester'] == $semesterListVal['sem_idPK'] ) ? 'selected' : '';
			$selectSemesterHTML .= '<option value="' . $semesterListVal['sem_idPK'] . '" ' . $semesterHTML . '>' . $semesterListVal['sem_desc'] . '</option>';
		}
	$selectSemesterHTML .= '</select>';
	
	$selectSubjectCourse = $DSC->getSubjectCourse();
	$selectSubjectnHTML = '<select name="txtsubject" id="txtsubject" class="select-auto-input"><option value=""></option>';
		if ( !empty($selectSubjectCourse) ) {
			foreach($selectSubjectCourse as $subjectCourseField => $selectSubjectList) {
				$selectSubjectnHTML .= '<optgroup label="' . $subjectCourseField . '">';
					foreach($selectSubjectList as $subjectListField => $subjectListVal) {
						$selectSubjectnHTML .= '<optgroup label="' . $subjectListField . '">';
							foreach($subjectListVal as $subjectVal) {
								$subjectHTML = ( $_GET['txtsubject'] == $subjectVal['subj_idPK'] ) ? 'selected' : '';
								$selectSubjectnHTML .= '<option value="' . $subjectVal['subj_idPK'] . '" ' . $subjectHTML . '>' . $subjectVal['subj_desc'] . ' (' . $subjectVal['subj_code'] . ')' . '</option>';
							}
						$selectSubjectnHTML .= '</optgroup">';
					}
				$selectSubjectnHTML .= '</optgroup">';
			}
		}
	$selectSubjectnHTML .= '</select>';
	
	$TEMP->set_var(array('search' 			=> $search,
						 'pagination'		=> $pagination,
						 'results'			=> "<strong>" . $listCountStudentInformation . "</strong> results",
						 'urlPage'			=> $urlPage,
						 'txtstudno'		=> $_GET['txtstudno'],
						 'txtfirst'			=> $_GET['txtfirst'],
						 'txtlast'			=> $_GET['txtlast'],
						 'semesterselect'	=> $selectSemesterHTML,
						 'subjectsselect'	=> $selectSubjectnHTML,
						 'header_table'		=> $headerTable,
						));
	
	$TEMP->set_var(array('reg_sub_menu'		=> $pageLib->registrarSubMenu(DIR_IMAGES),
						));
?>